/*
* $Id: JournalWin.cpp 72 2010-03-23 20:45:31Z volok-aleksej@yandex.ru $
*
* Copyright 2008-2009 by Volokitin Alexey
* All rights reserved
*
*/
#include "Common/include.h"
#include "Components/Journal/JournalInterface.h"
#include "Components/Components.h"
#include "Settings/InterfaceStn.h"
#include "Settings/SettingControlIds.h"
#include "JournalWin.h"
#include "CommandIds.h"
#include "HousingManagerDialog.h"

CJournalWin::CJournalWin(CJournalComponent* pComponent)
: m_pComponent(pComponent){m_pView = NULL;}
CJournalWin::~CJournalWin(){
	m_pView = NULL;
}
void CJournalWin::PostNcDestroy(){}

BOOL CJournalWin::OnWndMsg(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pResult){
	if(m_pView)
		*pResult = m_pView->OnWndMsg((unsigned int)message, (unsigned int)wParam, (long)lParam);
	return __super::OnWndMsg(message, wParam, lParam, pResult);
}

BEGIN_MESSAGE_MAP(CJournalWin, CFrameWnd)
	ON_WM_CREATE()
	ON_WM_SIZE()
	ON_WM_CLOSE()
	ON_WM_DESTROY()
	ON_COMMAND(ID_HOUSING, OnHousing)
	ON_COMMAND(ID_SETTINGS, OnSettings)
END_MESSAGE_MAP()

afx_msg int CJournalWin::OnCreate(LPCREATESTRUCT lpCreateStruct){
	int result = __super::OnCreate(lpCreateStruct);
	ISetting* pSettings =  IApplication::GetApp()->GetSettingsManager()->GetSetting(
							IApplication::GetApp()->GetLanguageManager()->GetString(JOURNAL_CAPTION_ID));
	m_pView = m_pComponent->GetView(pSettings->GetCurrentValue(COMBO_STYLE_ID));
	m_pView->CreateView((unsigned int)m_hWnd);

	m_toolBar.WindowCreate(this);

	return result;
}
afx_msg void CJournalWin::OnSize(UINT nType, int cx, int cy){
	CRect rect;
	GetClientRect(rect);
	m_toolBar.MoveWindow(0, 0, cx, SIZE_TOOLBAR);
}

afx_msg void CJournalWin::OnClose(){
	__super::OnClose();
}

afx_msg void CJournalWin::OnDestroy(){
	m_toolBar.DestroyWindow();
}

afx_msg void CJournalWin::OnHousing(){
	CHousingManagerDialog dialog(this);
	dialog.DoModal();
}

afx_msg void CJournalWin::OnSettings(){
	IApplication::GetApp()->GetVisualManager()->GetVisualComponent(
		IApplication::GetApp()->GetLanguageManager()->GetString(SETTINGS_ID))->CreateComponentFrame();
}